package com.hnedu.util;

import java.util.List;

public class SqlUtils {
  private SqlUtils() {
  }

  /*
   *
   */
  public static String createSql(String tableName, List params) {
    String[] parameter = null;
    String sql = "";
    String andStr = "";
    for (int i = 0; i < params.size(); i++) {
      parameter = (String[]) params.get(i);
      sql = sql + andStr + tableName + "." + parameter[0] + "='" + parameter[1] +
          "'";
      andStr = " AND ";
    }
    return sql;
  }

  public static String createLikeSql(String tableName, List params) {
    String[] parameter = null;
    String sql = "";
    String andStr = "";
    for (int i = 0; i < params.size(); i++) {
      parameter = (String[]) params.get(i);
      sql = sql + andStr + "left(" + tableName + "." + parameter[0] + "," +
          parameter[1].length() + ")='" + parameter[1] + "'";
      andStr = " AND ";
    }
    return sql;
  }
}
